package org.deadline.service.baseapp;

import java.util.List;
import org.deadline.model.baseapp.Organization;
import org.deadline.repository.baseapp.OrganizationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class OrganizationServiceImpl implements OrganizationService {

	@Autowired
    OrganizationRepository organizationRepository;

	public long countAllOrganizations() {
        return organizationRepository.count();
    }

	public void deleteOrganization(Organization organization) {
        organizationRepository.delete(organization);
    }

	public Organization findOrganization(Long id) {
        return organizationRepository.findOne(id);
    }

	public List<Organization> findAllOrganizations() {
        return organizationRepository.findAll();
    }

	public List<Organization> findOrganizationEntries(int firstResult, int maxResults) {
        return organizationRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveOrganization(Organization organization) {
        organizationRepository.save(organization);
    }

	public Organization updateOrganization(Organization organization) {
        return organizationRepository.save(organization);
    }
}
